package com.sunkingdom.qq.demo.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
@Aspect
public class AopDemo {
	
	@Pointcut("execution(* com.sunkingdom..*(..))")
	public void aspect() {

	}

	@Before("aspect()")
	public void before() {
		System.out.println("before");
	}

	@After("aspect()")
	public void after(JoinPoint joinPoint) {
		System.out.println("after");
	}
	
	@Around("aspect()")
	public void around(JoinPoint joinPoint){
		String startDate = new Date().toString();
		try {
			System.out.println(startDate);
			((ProceedingJoinPoint)joinPoint).proceed();
		} catch (Throwable e) {
			String endDate = new Date().toString();
			System.out.println(endDate);
			e.printStackTrace();
		}
		String endDate = new Date().toString();
		System.out.println(endDate);
		
	}
}
